package com.pgeneral.user.management.controller;

import com.pgeneral.user.management.config.ResultBean;
import com.pgeneral.user.management.entity.DepartmentInfo;
import com.pgeneral.user.management.entity.UserDepartmentInfo;
import com.pgeneral.user.management.service.UserDepartmentinfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 科室
 *
 * @author lenovo
 */
@Slf4j
@RestController
@RequestMapping("/user/departmentInfo")
public class UserDepartmentInfoController {

    @Autowired
    private UserDepartmentinfoService service;

    /**
     * 添加科室信息
     *
     * @param departmentInfos
     * @return
     */
    @PostMapping(value = "/saveInfo")
    public ResultBean insertDepartmentinfoTable(@RequestBody List<UserDepartmentInfo> departmentInfos) {
        log.info("调用科室save方法，方法参数为：{}", departmentInfos);
        int result = service.batchInsert(departmentInfos);
        return ResultBean.InsertSuccessResult(result);

    }

    /**
     * 科室查询
     *
     * @param departmentinfo
     * @return
     */
    @PostMapping(value = "/getInfo")
    public ResultBean getDepartmentinfoTable(@RequestBody UserDepartmentInfo departmentinfo) {
        log.info("调用科室get方法，方法参数为：{}", departmentinfo);
        List<UserDepartmentInfo> departmentInfos = service.getDepartmentinfoTable(departmentinfo);
        return ResultBean.Success(departmentInfos);

    }

    /**
     * 科室更新
     *
     * @param departmentInfos
     * @return
     */
    @PostMapping(value = "/updateInfo")
    public ResultBean updateDepartmentinfoTable(@RequestBody List<UserDepartmentInfo> departmentInfos) {
        log.info("调用科室update方法，方法参数为：{}", departmentInfos);
        int result = service.updateDepartmentinfoTable(departmentInfos);
        return ResultBean.InsertSuccessResult(result);

    }

    /**
     * 科室删除
     *
     * @param departmentIds
     * @return
     */
    @PostMapping(value = "/deleteInfo")
    public ResultBean deleteDepartmentinfoTable(@RequestBody List<String> departmentIds) {
        log.info("调用科室delete方法，方法参数为：{}", departmentIds);
        int result = service.deleteInfo(departmentIds);
        return ResultBean.InsertSuccessResult(result);
    }
}
